package news;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Temporal;

/**
 * This class holds the information of a news, which
 * are displayed at the start page of a lecture
 * @author Thorsten Ludwig
 */
@Entity
public class News implements Serializable {
    
    /**
     * the text of the news
     */
    private String message;
    /**
     * until this date the message will be dispayed
     */
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date expireDate;
    
    /**
     * if false, this news won't be displayed
     */
    private boolean active;
    @Id
    @GeneratedValue
    private Long id;
    
    public News() {
        
    }
    
    public News( String message, Date expireDate) {
        this.message = message;
        this.expireDate = expireDate;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }
    
    public boolean isValid() {
        Date d = new Date();
        return this.expireDate.after(d);
    }    
    
    public Date getExpireDate() {
        return expireDate;
    }

    public void setExpireDate(Date expireDate) {
        this.expireDate = expireDate;
    }

    public String getMessage() {
        System.out.print("Gebe Message aus: " + this.message);
        return message;
    }

    public void setMessage(String message) {
        System.out.println("Message geändert auf " + message);
        this.message = message;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
}